package com.git_taoxian.test6;

import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您的生日：格式为：yyyy-MM-dd");
        String birthday = sc.next();
//        创建解析字符串日历的格式对象
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-M-d");
//        解析
        LocalDate ld = LocalDate.parse(birthday, dtf);
        System.out.println(ld);
//        获取当前的日历
        LocalDate ldNow = LocalDate.now();

        Period period = Period.between(ld, ldNow);
        int years = period.getYears();
        int months = period.getMonths();
        int days = period.getDays();
        System.out.println("您已经活了："+years+"年零"+months+"月零"+days+"天了！");
    }
}
